package com.lhl.fw.db.biz.domain.entity;

import com.lhl.fw.db.entity.BaseEntity;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ManyToMany;
import java.util.HashSet;
import java.util.Set;

@Entity
@Getter
@Setter
@NoArgsConstructor
public class Teacher extends BaseEntity<String> {
	private String name;
	@ManyToMany(cascade=CascadeType.ALL,mappedBy="teachers",fetch=FetchType.LAZY)
	private Set<Student> students = new HashSet<>();
	
	public void addStudent(Student student) {
		this.students.add(student);
		student.getTeachers().add(this);
	}
	public void removeStudent(Student student) {
		if(this.students.contains(student)) {
			this.students.remove(student);
		}
	}
}
